@extends('layouts.app')

@section('title', isset($info->name)?translate($info, 'name'):translate('商品详情'))
@section('content')
<link href="/fontpage/css/mall.css" rel="stylesheet" type="text/css">
<div class="mall_main">
    <div class="header">
        <a href="javascript:history.back(-1)">
            <img src="/fontpage/images/zuojiantou.png">
        </a>
        <div>
            {{translate('商品详情')}}
        </div>
    </div>

    <div id="banner_box" class="box_swipe" >
        <ul >
        @foreach(translate($info, 'attachment') as $row)
            <li >
                <img src="{{url('upload/'.$row)}}">
            </li>
        @endforeach
        </ul>
        <ol>
        @foreach(translate($info, 'attachment') as $row)
            <li class=""></li>
            &nbsp;
            @endforeach
        </ol>
    </div>
    <div class="des_goods">
        <p>
            {{translate($info, 'title')}}
        </p>



        <p>
            <span class="pr">{{translate('价格')}}:</span>
            <span class="sp_style3">
                ¥{{$info->price}}
            </span>
        </p>

        <hr>
        <div class="spec_select">
            <ul>
                <li>
                    <span>{{translate('商品规格')}}：</span>
                    	@php
                        $firsInfo = (object)[];
                        @endphp
                        @foreach($info->goods_attributes as $k=>$row)
                        @if($k==0)
                        @php
                        $firsInfo = $row;
                        @endphp
                        @endif
                            <em value="{{$row->id}}"
                            @if($k==0)
                            class="click"
                            @endif
                            >{{translate($row, 'name')}}</em>
                    	@endforeach
                </li>
            </ul>
        </div>
        <hr>
        <div class="goods_activity">






            <div class="num">
                <span>{{translate('数量')}}：</span>
                <span id="a" class="Spinner">
                </span>
                <span class="stock">{{translate('库存')}}
                    @if(!empty($firsInfo))
                        {{$firsInfo->number}} {{translate($firsInfo, 'unit')}}
                    @endif
                </span>
            </div>
            <!--<p>
                <span class="pr">{{translate('服务承诺')}}：</span><span>{{translate('7天无理由退货 正品保证')}}</span>
            </p>-->
            <p class="pay_type">
                <span class="pr">{{translate('支付类别')}}：</span>
                <span>
						<img src="/fontpage/images/zhifubao.png" width="32" height="30">
						{{translate('支付宝')}}
						</span>
                <span>
						<img src="/fontpage/images/weixin.png" width="32" height="30">
						{{translate('微信')}}
						</span>
                <span>
						<img src="/fontpage/images/xianxiazhifu.png" width="28" height="28">
						{{translate('线下支付')}}
                </span>
            </p>
            <p>
                <span style="margin-left: 6.6%">{{translate('留 言')}}：</span><span><input type="text" name="detail" placeholder="{{translate('说点什么吧')}}..." id="message" style="border: 1px solid #cccccc ;width: 70%;padding-bottom: 40px; border-radius: 4px;color: #666666;font-size: 14px;margin-left: 1.8%"></span>
            </p>
        </div>
    </div>

    <div class="box_list">
        <ul class="box_nav">
            <li class="current">
                <a>
                    {{translate('商品详情')}}
                </a>
            </li>
            <li>
                <a>
                    {{translate('商品参数')}}
                </a>
            </li>
        </ul>
        <div class="goods_box">
            <!-- 商品其他图片 -->


                {!!translate($info, 'content')!!}


        </div>
        <div class="goods_box" style="display: none">
            <div class="deal_list">
            @php
            $i=1;
            @endphp
            @foreach(translate($info, 'parm') as $k=>$row)
                <p>
                    <span>产品参数{{$i}}:</span><span>{{$row}}</span>
                    @php
            $i++;
            @endphp
                </p>
            @endforeach

            </div>
        </div>
    </div>
    <div class="bottomdiv clearfix">
        <div class="inner clearfix">
            <div class="fl btn_sure">
                <a class="buy">
                    {{translate('立即购买')}}
                </a>
            </div>
            <div class="fl btn_buy_detail">
                <a class="addshop_cat">
                    {{translate('加入购物车')}}
                </a>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript">$(function () {
    new Swipe(document.getElementById('banner_box'), {
        speed: 500,
        auto: 3000,
        callback: function () {
            var lis = $(this.element).next("ol").children();
            lis.removeClass("on").eq(this.index).addClass("on");
        }
    });
});</script>
<script type="text/javascript">

    $(function () {

        $(".spec_select ul li em").click(function () {
            $(this).addClass("click").siblings().removeClass("click");
			ajaxurl('',{fid:$(this).attr("value")},function(jsondata){
                $(".sp_style3").text("¥"+jsondata.price);

                if(getQueryString('jp' == 1)) {
                	$(".stock").text("{{translate('库存')}}: "+jsondata.number + " "+ jsondata.runit);
                }else{
                	$(".stock").text("{{translate('库存')}}: "+jsondata.number + " "+ jsondata.unit);
                }
				});
			return


    })

        $(".addshop_cat").click(function () {
            //console.log( "fid:"+$(".click").attr("value") );
            //console.log("amount:"+$(".Amount").val() );
            var url="/user/addCart";

            var $choice = $(".click");
            if($choice.length==0)
            {
                alert("{{translate('请选择规格')}}");
                return;
            }

            var info={goods_attr_id:$(".click").attr("value"),number:$('.Amount').val(),goods_id:{{$info->id}},detail:$("#message").val()};
			ajaxurl(url, info, function(res){
				if(res.status == 1) {
					layer.msg("{{translate('加入成功')}}");
					}else{
						layer.msg(res.msg);
						}
				})

        });


        $(".buy").click(function () {
          var url="{{JpUrl('/user/addCart')}}";
          var info={goods_attr_id:$(".click").attr("value"),number:$('.Amount').val(),goods_id:{{$info->id}},detail:$("#message").val()};
          ajaxurl(url, info, function(res){
            if(res.status == 1) {
              //提交购物车
              var json = new Array();
              json[1] = res.id
              var form = $('<form>{{ csrf_field() }}</form>');
              form.attr('action', "{{JpUrl('/user/cartCommit')}}");
              form.attr('method', 'post');
              form.attr('target', '_self');

              var input1 = $("<input type='hidden' name='json' />");
              input1.attr('value', json);
              form.append(input1);

              var input2 = $("<input type='hidden' name='type' />");
              input2.attr('value', 1);
              form.append(input2);

              form.appendTo("body");
              form.css('display', 'none');
              form.submit();
              }else{
                layer.msg(res.msg);
                }
            })



        });


    })
</script>
<script type="text/javascript" src="/fontpage/js/jquery.Spinner.js"></script>
<script src="/fontpage/js/swipe2.js" type="text/javascript"></script>
<script type="text/javascript">$(function () {
    $("#a").Spinner({
        value: 1,
        min: 1,
        len: 3,
        max: 10000
    });
});</script>
<script type="text/javascript">jQuery(function ($) {
    $('.box_list ul li').click(function () {
        var index = $('.box_list ul li').index(this);
        $(this).addClass('current').siblings('li').removeClass('current');
        $('.box_list .goods_box:eq(' + index + ')').show().siblings('.goods_box').hide();
    })
})</script>
@endsection
@section('footer')
     @include('common.footer')
@stop
